SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
GO

PRINT '---- tblComplex'

PRINT '-- Table title'
INSERT tblUFGTableTitles (utt_Tablename, utt_Languagename, utt_Title, utt_Description)
VALUES ('tblComplex','Nederlands','Complexen','Complex gegevens')

PRINT '-- Column titles'
INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_Clubname','Nederlands','Complex eigenaar','U dient de eigenaar van het complex in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_Complexname','Nederlands','Complexnaam','U dient complexnaam in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_adres','Nederlands','Adres','U dient adres in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_zipcode','Nederlands','Postcode','U dient een postcode in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_City','Nederlands','Plaats','U dient een plaats in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_Telephone','Nederlands','Telefoonnummer','U dient een telefoonnummer in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblComplex','cpx_Description','Nederlands','Beschrijving','U kunt hier een beschrijving in vullen.')

UPDATE tblUFGColumns SET ucl_PanelNumber = NULL WHERE ucl_TableName = 'tblComplex'
DELETE tblUFGPanelTitles WHERE upt_TableName = 'tblComplex'
DELETE tblUFGPanels WHERE upn_TableName = 'tblComplex'

INSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblComplex',1,1,4,1)
INSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblComplex',2,2,1,1)

UPDATE tblUFGColumns 
SET ucl_PanelNumber = 1 
WHERE ucl_TableName = 'tblComplex' 
AND ucl_ColumnName NOT IN ('cpx_Description')

PRINT '-- Row Rights'
INSERT tblUFGRowRights
(urr_TableName,urr_RoleName,urr_SQLInsertExpression,urr_SQLUpdateExpression,urr_SQLDeleteExpression)
VALUES
('tblComplex','Voorzitter Club',
NULL,
'EXISTS(SELECT * 
		FROM tblChairmen 
		INNER JOIN tblPersons ON prs_ID = chm_PersonID 
		WHERE prs_Username = @UFGUsername
		AND chm_ClubName = @cpx_Clubname)',
'EXISTS(SELECT * 
		FROM tblChairmen 
		INNER JOIN tblPersons ON prs_ID = chm_PersonID 
		WHERE prs_Username = @UFGUsername
		AND chm_ClubName = @cpx_Clubname)')
		
INSERT tblUFGRowRightTitles
(urt_TableName,urt_RoleName,urt_Language,urt_InsertDescription,urt_UpdateDescription,urt_DeleteDescription)
VALUES ('tblComplex','Voorzitter Club','Nederlands',
'Voorzitters mogen complexen van hun eigen club toevoegen',
'Voorzitters mogen complexen van hun eigen club wijzigen',
'Voorzitters mogen complexen van hun eigen club verwijderen')

UPDATE tblUFGForeignKeyColumns
SET ufc_AdditionalWhere = 'dbo.fnGetClubnameByUser(@UFGUsername) IN (clb_Name, ''*'')'
WHERE ufc_ForeignKeyName = 'FK_cpx_Clubname'
AND ufc_TableName = 'tblComplex'
AND ufc_ColumnName = 'cpx_Clubname'
AND ufc_ReferenceTableName = 'tblClubs'
AND ufc_ReferenceColumnName = 'clb_Name'
GO

PRINT '-- Display'
UPDATE tblUFGTables SET utb_DisplayInCategory = 'MAINTABLES' WHERE utb_TableName = 'tblComplex'